﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using HTComics.Web.Common;
using DB = HTComics.Data;


namespace HTComics.Web.Home
{
    public partial class ContactUs : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            MailMessage msg;

            SmtpClient client = new SmtpClient();
            client.Host = Defaults.MailSetup.MailServer;
            client.Port = Defaults.MailSetup.MailPort;

            //To Admin
            msg = new MailMessage();
            msg.IsBodyHtml = true;
            msg.Body = GetHtml();
            msg.From = new MailAddress(txtEmail.Value);
            msg.To.Add(new MailAddress(Defaults.MailSetup.FeedbackAccount));
            msg.Subject = "User Query Received";
            client.Send(msg);

            //To User
            msg = new MailMessage();
            msg.IsBodyHtml = true;
            msg.Body = GetHtml();
            msg.From = new MailAddress(Defaults.MailSetup.NoReplyAccount);
            msg.To.Add(new MailAddress(txtEmail.Value));
            msg.Subject = "[www.ht-comics.com] Query Sent";
            client.Send(msg);

            DB.HTCUser.CreateFeedback(txtName.Value, txtPhone.Value, txtEmail.Value, txtQuery.Value);

            this.ClientScript.RegisterStartupScript(typeof(Page), "", "<script type=\"text/javascript\">clearFields();success();</script>");
        }

        private string GetHtml()
        {
            string html = "";

            html += "Name: " + txtName.Value + "<br /></br>";
            html += "Phone: " + txtPhone.Value + "<br /></br>";
            html += "Email: " + txtEmail.Value + "<br /></br>";
            html += "Type: " + selType.Items[selType.SelectedIndex].Text + "<br /></br>";
            html += "Query: " + txtQuery.Value + "<br /></br>";

            return html;
        }
    }
}